package com.ruoyi.supplier.manager;


import cn.hutool.core.convert.Convert;
import com.ruoyi.supplier.domain.bo.RefundBo;
import com.ruoyi.supplier.domain.bo.RefundItemBo;
import com.ruoyi.supplier.domain.vo.refund.RefundCreateVo;
import com.ruoyi.supplier.service.IRefundItemService;
import com.ruoyi.supplier.service.IRefundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RefundManager {

    @Autowired
    private IRefundService refundService;

    @Autowired
    private IRefundItemService refundItemService;

    public int create(RefundCreateVo createVo) {
        RefundBo refundBo = Convert.convert(RefundBo.class,createVo);
        refundService.insertByBo(refundBo);
        createVo.getItems().stream().map(refundItemVo -> {
            RefundItemBo itemBo = Convert.convert(RefundItemBo.class,refundItemVo);
            itemBo.setSupplierId(createVo.getSupplierId());
            return itemBo;
        }).forEach(refundItemBo -> refundItemService.insertByBo(refundItemBo));
        return 1;
    }
}
